package com.hzy.fivepalace.admin.controller;

import com.hzy.fivepalace.admin.annotation.Login;
import com.hzy.fivepalace.admin.controller.base.BaseController;
import com.hzy.fivepalace.admin.service.AdminNewCategoryService;
import com.hzy.fivepalace.common.page.TableDataInfo;
import com.hzy.fivepalace.db.vo.wx.WxCategoryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;


/**
 * 管理员消息推送服务
 *
 * @author gejian
 */
@RestController
@RequestMapping("/admin/newCategory")
@Api(tags = "新类目管理")
@ResponseBody
@Login
public class AdminNewCategoryController extends BaseController {

    @Resource
    private AdminNewCategoryService adminNewCategoryService;


    /**
     * 父级类目列表-分页
     *
     * @param page
     * @param size
     * @return
     */
    @PostMapping("/getFatherCategoryList")
    @ApiOperation(value = "父级类目列表-分页")
    public TableDataInfo getFatherCategoryList(
            @ApiParam(value = "页码", defaultValue = "1") @RequestParam(defaultValue = "1") Integer page,
            @ApiParam(value = "分页大小", defaultValue = "10") @RequestParam(defaultValue = "100") Integer size
    ) {
        return adminNewCategoryService.getFatherCategoryList(page, size);
    }


    @PostMapping("/delCategory")
    @ApiOperation(value = "删除类目")
    public Object delCategory(
            @ApiParam(value = "分类id") @RequestParam(value = "categoryId") @NotNull Integer categoryId
    ) {

        return adminNewCategoryService.delCategory(categoryId);
    }


    /**
     * 新增或修改类目
     *
     * @param vo
     * @param sort
     * @return
     */
    @PostMapping("/addCategoryOrUpd")
    @ApiOperation(value = "新增或修改类目")
    public Object addCategoryOrUpd(WxCategoryVo vo,
                                   @ApiParam(value = "排序") @RequestParam(value = "sort", required = false) Integer sort) {
        return adminNewCategoryService.addCategoryOrUpd(vo, sort);
    }


}
